import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:qaun_ni_dev/utils/request.dart';
import 'package:qaun_ni_dev/utils/toast.dart';

class AdminAdd extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('添加管理员'),
      ),
      body: Container(
        padding: EdgeInsets.all(10),
        child: Column(
          children: <Widget>[
            _inputAddText(context)
          ],
        ),
      ),
    );
  }


  Widget _inputAddText (context) {
    TextEditingController userAccount = TextEditingController();
    TextEditingController remark = TextEditingController();
    TextEditingController userPassword = TextEditingController();
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: userAccount,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '账号名称',
              hintText: '请输入你的账号名',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: userPassword,
            readOnly: false,
            obscureText: true,
            decoration: InputDecoration(
              labelText: '账号密码',
              hintText: '请输入你的密码',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: remark,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '账号备注',
              hintText: '请输入你的备注信息',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        RaisedButton(
          child: Text('提交新增'),
          onPressed: () async {
            var formData = {
              'userAccount':userAccount.text,
              'remark':remark.text,
              'userPassword':userPassword.text,
            };
            await requestPost(context,'/sysUser/add',formData: formData).then((value) {
              var responseData = json.decode(value.toString());
              if(responseData['code'] == 200) {
                Toast.toast(context,msg: '数据删除成功');
                Navigator.pushNamed(context, '/AdminPagess');
              } else {
                Toast.toast(context,msg: '数据删除失败，请重试');
              }
              print(responseData);
            });
          },
        )
      ],
    );
  }
}
